package com.atguigu.spzx.common.exception;

import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author syh
 * @create 2023-08-14 17:19
 */
//com.atguigu.spzx.common.exception
@RestControllerAdvice
//@Slf4j
//@Log
public class GuiguExceptionHandler {
    //创建一个Exception类型的异常的处理器
    @ExceptionHandler(value = Exception.class)
    public Result<Object> exception(Exception e){
//        log.
        System.out.println(e.getMessage());
        return Result.build(null,ResultCodeEnum.UNKNOW_ERROR );
    }
    //自定义类型异常的处理器
    @ExceptionHandler(value = GuiguException.class)
    public Result<Object> exception(GuiguException e){
        System.out.println(e.getMessage());
        return Result.build( null,e.getCode(), e.getMessage());
    }
}
